let price = document.getElementsByClassName('price')[0]
// let { offsetTop, offsetLeft, offsetParent, offsetWidth, offsetHeight } = price
// console.log('offsetTop:', offsetTop)
// console.log('offsetLeft:', offsetLeft)
// console.log('offsetParent:', offsetParent)
// console.log('offsetWidth:', offsetWidth)
// console.log('offsetHeight:', offsetHeight)

let tops = 0
while (1) {
  console.log(price)
  // 获得price对象的top值进行累积
  tops += price.offsetTop
  let offsetParent = price.offsetParent
  if (!offsetParent) {
    break
  }
  price = offsetParent
}
console.log(tops)

// scrollTop
// scrollLeft
// 给文档或窗口绑定滚动事件
let back = document.getElementsByClassName('back')[0]
window.onscroll = function () {
  // html元素
  let html = document.documentElement
  // body元素
  let body = document.body
  // 滚动距离
  let scrollTop = html.scrollTop || body.scrollTop
  console.log(scrollTop)
  if (scrollTop > 200) {
    back.style.display = 'flex'
  } else {
    back.style.display = 'none'
  }
}

// 点击返回顶端
back.onclick = function () {
  window.scrollTo({ letf: 0, top: 0, behavior: 'smooth' })
}
